﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Abp.Domain.Services;
using Abp.UI;
using FwProject.Core.AppVersion;
using FwProject.ShoppingMall.Com;
using FwProject.ShoppingMall.EventAdvertising;
using FwProject.ShoppingMall.Shop;

namespace FwProject.Manager
{
    public class ShopSecondkillManager : IDomainService
    {
        private readonly IRepository<ShopSecondkill, Guid> _shopSecondkillRepository;
        private readonly IRepository<ShopProduct, Guid> _shopProductRepository;

        public ShopSecondkillManager(IRepository<ShopSecondkill, Guid> shopSecondkillRepository,
            IRepository<ShopProduct, Guid> shopProductRepository)
        {
            _shopSecondkillRepository = shopSecondkillRepository;
            _shopProductRepository = shopProductRepository;
        }
        /// <summary>
        ///创建一个秒杀
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<Guid> CreateShopSecondkill(ShopSecondkill model)
        {
        
            return await _shopSecondkillRepository.InsertAndGetIdAsync(model);
        }
        /// <summary>
        ///  修改一个秒杀
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>

        public async Task UpdateShopSecondkill(ShopSecondkill model)
        {
            await _shopSecondkillRepository.UpdateAsync(model);
        }
      
        /// <summary>
        /// 删除一个秒杀活动
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task DeleteShopUserCoupon(ShopSecondkill model)
        {
            await _shopSecondkillRepository.DeleteAsync(model);
            var m=_shopProductRepository.Get(model.ShopProductId);
             m.ShopProductFlag = ShopProductFlag.正常;
        }
    }
}
